
var vm = new Vue({
    el : "#SalesOrder",
    data : {
        record:{},
        sels:[],
        table: null
    },
    init:function(){
        var _self = this;
        layui.use(['layer'], function(){
            layer = layui.layer;
        });
        this.$nextTick(function() {
            this.$http.post("../SalesOrder/SalesLists",{},{emulateJSON: true}).then(function(res){
                if(res.ok){
                    _self.tableData = res.body.salesLists;
                    _self.$options.methods.renderTable(_self,res.body.SalesLists);
                }
            });
        });
    },
    methods: {
        boxLists: function(val){
            var _self = this;
            var rfid = $("#rfid").val();
            if (rfid==null || rfid.trim() =='') {
                alert("请先扫描RFID！");
                return;
            }
            var data ={
                status : val,
                rfid:rfid,
                emesoJobOrderExeId:_self.emesoJobOrderExeId
            };
            this.$nextTick(function() {
                this.$http.post(host +"SalesOrder/boxLists",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.vueAlert("操作成功！");
                    }else{
                        layer.msg("操作失败");
                    }
                });
            });
        },
        getleftRfidList: function(event){
            document.getElementById("jobCode").innerText='工单号：';
            document.getElementById("productName").innerText='型体：';
            document.getElementById("colorName").innerText='颜色：';
            document.getElementById("inTime").innerText='下单时间：';
            document.getElementById("size").innerText='尺码：';
            document.getElementById("manName").innerText='收件人：';
            document.getElementById("address").innerText='收件人地址：';
            var _self = this;
            var code = document.getElementById("code").value;   //作业工单RFID
            if(code == null || code.trim() ==''){
                _self.vueAlert("请扫描RFID！");
            }
            _self.changeRfid(_self,code);


        },
        changeRfid: function(_self,code){

            var data ={
                code : code
            };
            var salesDataByCode = [];
            _self.$nextTick(function() {
                _self.$http.post(host +"SalesOrder/rfidLists",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.salesDataByCode = res.body.salesDataByCode;
                        if(_self.salesDataByCode == null || _self.salesDataByCode.length == 0){
                            _self.vueAlert("此工单不存在！");
                            return;
                        }
                        salesDataByCode =  _self.salesDataByCode;
                        if(salesDataByCode[0].JOBCODE != null && salesDataByCode[0].JOBCODE !=''){
                            document.getElementById("JOBCODE").innerText="工单号："+salesDataByCode[0].JOBCODE;
                        }
                        if(salesDataByCode[0].PRODUCTNAME != null && salesDataByCode[0].PRODUCTNAME !=''){
                            document.getElementById("productName").innerText="型体："+salesDataByCode[0].PRODUCTNAME;
                        }
                        if(salesDataByCode[0].COLORNAME != null && salesDataByCode[0].COLORNAME !=''){
                            document.getElementById("colorName").innerText="颜色："+salesDataByCode[0].COLORNAME;
                        }
                        if(salesDataByCode[0].INTIME != null && salesDataByCode[0].INTIME !=''){
                            document.getElementById("inTime").innerText="下单时间："+salesDataByCode[0].INTIME;
                        }
                        if(salesDataByCode[0].SIZE != null && salesDataByCode[0].SIZE !=''){
                            document.getElementById("size").innerText="尺码："+salesDataByCode[0].SIZE;
                        }
                        if(salesDataByCode[0].MANNAME != null && salesDataByCode[0].MANNAME !=''){
                            document.getElementById("manName").innerText="收件人："+salesDataByCode[0].MANNAME;
                        }
                        if(salesDataByCode[0].ADDRESS != null && salesDataByCode[0].ADDRESS !=''){
                            document.getElementById("address").innerText="收件人地址："+salesDataByCode[0].ADDRESS;
                        }
                        _self.emesoJobOrderExeId = salesDataByCode[0].EMESO_JOB_ORDER_EXE_ID;
                    }
                });
            });
        },
        reset:function(data){
            window.location.reload();
        },
        vueAlert:function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        },
        renderTable: function(_self,data){
            layui.use(['form','table','laydate'], function(){
                _self.table = layui.table;
                var form = layui.form;

                _self.table.render({
                    elem: '#salesListTable',
                    width: 'full-20',
                    height: 'full-150',
                    cols: [[ //标题栏
                        { type:'numbers',title:'序号'},
                        { field: 'JOBCODE', title: '工单号',width: 200},
                        {field: 'PRODUCTNAME', title: '款式',width: 200, align:'center' },
                        {field: 'COLOR', title: '颜色', width: 180,align:'center'},
                        {field: 'SALESNAME', title: '收货人', minWidth: 160,align:'center'},
                        {field: 'ADDRESS', title: '收货人地址', width: 160,align:'center'},
                        {field: 'INTIME', title: '发货时间', minWidth: 160,align:'center',templet: "<div>{{layui.util.toDateString(d.EXE_DATE_FROM, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                        {field: 'JOBNAME', title: '发货人', width: 160,align:'center'},
                        {field: 'BOXNAME', title: '包装盒条码', width: 150,align:'center'},
                        {field: 'WLID', title: '物流单号', minWidth: 80,align:'center'}

                    ]],
                    data:data,
                    page: true, //是否显示分页
                    limits: [10, 20, 50],
                    limit: 15 //每页默认显示的数量
                });
            });
        }
    }
});